function h = bvqxfilehead(filename)
% bvqxfilehead  - read only the header part of a BVQXfile format
%
% FORMAT:       h = bvqxfilehead(filename)
%
% Input fields:
%
%       filename    filename of BVQX file
%
% Output fields:
%
%       h           read header

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~ischar(filename) || ...
    numel(filename) ~= size(filename, 2) || ...
    numel(filename) < 5
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid filename argument.' ...
    );
end

% get types
bvqxroot = BVQXfile;

% check type of file
[filepath{1:3}] = fileparts(filename);
if ~isfield(bvqxroot.Extensions, lower(filepath{3}(2:end)))
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid file extension %s.', ...
        filepath{3} ...
    );
end

% get bff/tff format
fileform = bvqxroot.Extensions.(lower(filepath{3}(2:end)));
formtype = fileform{1}(end-2:end);
formspec = bvqxroot.Formats.(formtype)(fileform{2});

% call either xffio
switch (formtype)
    
    % BFF coding
    case {'bff'}
        h = bffio(filename, formspec, '-fh');
        
    % TFF coding
    case {'tff'}
        h = tffio(filename, formspec, '-fh');
        
    % unknown coding
    otherwise
        error( ...
            'BVQXtools:InternalError', ...
            'Unknown specification format: %s.', ...
            formtype ...
        );
end
